@extends('admin._layouts.default')

@section('main')

      <div class="row-fluid ">
        <div class="span12 box gradient ">
      <div class="title">
            <div class="row-fluid">
                <h3>
                    <select class="inline-block  pull-right " id="shaixuan_state" style="width: 150px;"  >
                        <option value="大润发销售" >大润发销售</option>
                        <option value="服务网点销售" >服务网点销售</option>
                        <option value="活动销售" >活动销售</option>
                        <option value="客户转介绍" >客户转介绍</option>
                        <option value="其他" >其他</option>
                    </select>
                    <a href="javascript:void (0)" onclick="shaixuan_mounts()"  class="btn btn-success btn-mini pull-right mg5"><i class="fa fa-edit"></i> 筛选来源</a>

                    <select class="inline-block  pull-right " id="export_state" style="width: 150px;"  >
                        <option value="all" >全部</option>
                        <option value="0" >申请试用中</option>
                        <option value="1" >试用中</option>
                        <option value="2" >订购中</option>
                        <option value="3" >使用中</option>
                        <option value="4" >拆机中</option>
                        <option value="5" >已拆机</option>
                        <option value="7" >换芯中</option>
                        <option value="8" >维修中</option>
                    </select>
                    <a href="javascript:void (0)" onclick="export_mounts()"  class="btn btn-success btn-mini pull-right mg5"><i class="fa fa-edit"></i> 导出</a>
                    <a href="{{ route('admin.services.mounts') }}"  class="btn btn-warning btn-mini pull-right mg5"><i class="fa fa-edit"></i> 查看全部</a>
                <a href="{{ route('admin.services.mounts', array('state' => 0)) }}"  class="btn btn-warning btn-mini pull-right mg5"><i class="fa fa-edit"></i> 只看申请使用</a>
                <a href="{{ route('admin.services.mounts', array('type' => 'no')) }}"  class="btn btn-warning btn-mini pull-right mg5"><i class="fa fa-edit"></i> 查看未定位小区客户</a>
                <a href="{{ route('admin.services.mounts', array('state' => 1)) }}"  class="btn btn-warning btn-mini pull-right mg5"><i class="fa fa-edit"></i> 只看试用</a>
                 <a href="{{ route('admin.mounts.create') }}"  class="btn btn-info btn-mini pull-right" style="margin:5px 5px 0 0"><i class="fa fa-edit"></i> 新增</a>
                  <i class="fa fa-shopping-cart"></i> 客户资料管理
                </h3>
            </div>
        </div><!-- End .title -->
        <div class="content min_h500">

            <table id="datatable_in" class="responsive table table-striped" style="width:100%;margin-bottom:0; ">
              <thead>
               <tr>
                 {{--<th width="80">--}}
                   {{--头像--}}
                  {{--</th>--}}
                   <th width="160">
                       姓名
                   </th>
                   <th width="160">
                       所属直营商
                   </th>
                   <th>
                       小区
                   </th>
                  <th width="360">
                    联系方式
                  </th>
                  <th>
                    状态
                  </th>
                  <th>

                  </th>
                  <th>
                    机型|二维码编号
                  </th>
                   <th>
                       安装时间
                   </th>
                   <th>
                       客户来源
                   </th>
                  @if($user->hasAccess('admin'))
                  <th>
                  操作
                  </th>
                   @elseif($user->hasAccess('section'))
                   <th>
                        装机秀
                   </th>
                  @endif
                 {{--<th width="160">--}}
                   {{--操作--}}
                 {{--</th>--}}
               </tr>
              </thead>
              <tbody>
                @foreach($mounts as $mount)
               <tr>
                  {{--<td>--}}
                   {{--<img class="thumbnail small" src="img/news1.jpg">--}}
                  {{--</td>--}}
                   <td>
                       <i class="fa fa-user"></i> {{ $mount->mount_name }}  @if($mount->sex == 1)先生 @else 女士 @endif
                   </td>
                   <td>

                       @if($user->hasAccess('city'))
                           <select class="inline-block" style="width: 150px;"  onchange= "select_section('{{ $mount->id }}',this.options[this.options.selectedIndex].value)">
                               @if(!$mount->customer->area)
                                   <option value="" selected >无</option>
                               @endif
                               @foreach($sections as $section)
                                   <option value="{{ $section->area}}" @if($mount->customer->area == $section->area)selected @endif >{{ $section->areaname->name }}</option>
                               @endforeach
                           </select>
                       @else
                           <i class="fa fa-user"></i> {{ $mount->customer->areaname->name }}
                       @endif
                   </td>
                   <td>

                       @if($user->hasAccess('city'))
                           <select class="inline-block" style="width: 150px;"  onchange= "select_xiaoqu('{{ $mount->id }}',this.options[this.options.selectedIndex].value)">

                               @foreach($xiaoqus as $xiaoqu)
                                   <option value="{{ $xiaoqu->id }}" @if($mount->xiaoqu->id == $xiaoqu->id)selected @endif >{{ $xiaoqu->name }}</option>
                               @endforeach
                           </select>
                       @else
                           <i class="fa fa-user"></i> {{ $mount->xiaoqu->name }}
                       @endif
                   </td>
                 <td>
                    <i class="fa fa-mobile"></i> {{ $mount->mount_mobile }}<i class="fa fa-home"></i> {{ $mount->xiaoqu->name }}<i class="fa fa-child"></i> {{ $mount->address }}
                  </td>
                  <td>

                      <select class="inline-block" style="width: 150px;"  onchange= "select_type('{{ $mount->id }}',this.options[this.options.selectedIndex].value)">
                          <option value="0" @if($mount->state == 0)selected @endif >申请试用中</option>
                          <option value="1" @if($mount->state == 1)selected @endif >试用中</option>
                          <option value="2" @if($mount->state == 2)selected @endif >订购中</option>
                          <option value="3" @if($mount->state == 3)selected @endif >使用中</option>
                          <option value="4" @if($mount->state == 4)selected @endif >拆机中</option>
                          <option value="5" @if($mount->state == 5)selected @endif >已拆机</option>
                          <option value="7" @if($mount->state == 7)selected @endif >换芯中</option>
                          <option value="8" @if($mount->state == 8)selected @endif >维修中</option>
                      </select>
                 </td>
                 <td>
                 @if($mount->type == 'old')
                 老客户
                 @endif
                 </td>
                 <td>{{ $mount->machine->name }} | <a href="/admin/mounts/get_mount_code?id={{ $mount->code }}">{{ $mount->code }}</a></td>
                 <td>
                 {{ $mount->created_at }}
                 </td>
                   <td>
                       {{ $mount->from }}
                   </td>
                 <td>
                    <div class="btn-group1">
                  @if($user->hasAccess('admin'))
                      <a class="btn btn-small" href="{{ route('admin.mounts.edit',$mount->id) }}" >修改</a>
                      {{--<a class="btn btn-small" rel="tooltip" data-placement="left" data-original-title="主动维护" data-toggle="modal" data-target="#order_work"><i class="fa fa-wrench"></i></a>--}}
                    @elseif($user->hasAccess('section'))

                            <a class="btn btn-small" href="{{ route('admin.mounts.show',$mount->id) }}" >修改</a>
                        @endif

                    @if($mount->state == 0)
                     <a class="btn btn-inverse btn-small" onclick="set_delete('{{ $mount->id }}');"   rel="tooltip" data-placement="bottom" data-original-title="删除订单" data-toggle="modal" data-target="#confirm_alert"><i class="gicon-remove icon-white"></i></a>

                  @endif
                   </div>
                 </td>

               </tr>
               @endforeach


               </tbody>
            </table>
                <div class="row-fluid control-group">



                    <div class="pagination pull-right ">
                      {{ $mounts->links() }}
                    </div>
                </div>
                <br/>


            </div>
        </div>
        <!-- End box -->
      </div>


@stop


@section('modals')
<div id="work_out" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 class="modal-title" id="myModalLabel">员工列表</h3>
      </div>
      <div class="modal-body">
          <div class="form-row control-group row-fluid">
            <div class="controls span9">
              <div class="input-append row-fluid">
                <input type="text" class="span5" id="search-input" placeholder="搜索员工">
                <button type="submit" class="btn">搜索</button>
              </div>
            </div>
          </div>

          <form class="form-horizontal" action="#">
          <table class="table">
            <thead>
            <tr>
              <th width="60">
                选择
              </th>
              <th width="80">
                头像
              </th>
              <th>
                姓名
              </th>
            </tr>
            </thead>
            <tbody>
            <tr>
              <td>
                <input type="radio" name="radio" value="11" checked="CHECKED"/>
              </td>
              <td>
               <img class="thumbnail small" src="img/message_avatar2.png">
              </td>
              <td>
                王小山
              </td>
            </tr>
            <tr>
              <td>
                <input type="radio" name="radio" value="22"/>
              </td>
              <td>
               <img class="thumbnail small" src="img/message_avatar4.png">
              </td>
              <td>
                王小峰
              </td>
            </tr>
            <tr>
              <td>
                <input type="radio" name="radio" value="222"/>
              </td>
              <td>
               <img class="thumbnail small" src="img/message_avatar2.png">
              </td>
              <td>
                王大宝
              </td>
            </tr>
            <tr>
              <td>
                <input type="radio" name="radio" value="333"/>
              </td>
              <td>
               <img class="thumbnail small" src="img/message_avatar4.png">
              </td>
              <td>
                王适龄
              </td>
            </tr>
            <tr>
              <td>
                <input type="radio" name="radio" value="333"/>
              </td>
              <td>
               <img class="thumbnail small" src="img/message_avatar2.png">
              </td>
              <td>
                肖萨格
              </td>
            </tr>
            </tbody>
          </table>
        </form>

      </div>
      <div class="modal-footer">
                <div class="row-fluid control-group">
                  <div class="pull-left span6" action="#">
                    <div class="pagination pull-left ">
                      <ul>
                       <li><a href="#">上一页</a></li>
                        <li><a href="#">下一页</a></li>
                      </ul>
                    </div>
                  </div>
                  <div class="span6">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary">确定</button>
                  </div>
                </div>


      </div>
    </div>
  </div>
</div>

<div id="confirm_alert" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
  <form action="{{ route('admin.services.deletemount') }}" id="form_delete" method="post">
    <div class="modal-content">
      <div class="modal-header">
      <input type="hidden" name="delete_id" id="delete_id" value="">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 class="modal-title" id="myModalLabel">确定本次操作吗？</h3>
      </div>
      <div class="modal-body">
        <i class=" icon-warning-sign color_red pull-left fs_24"></i>

        <p>一旦【确定】，本次操作不可撤销。</p>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" onclick="delete_it();" class="btn btn-primary">确定</button>
      </div>
    </div>
    </form>
  </div>
</div>
@stop


@section('script')
<script language="javascript" type="text/javascript" src="{{ URL::asset('ad/js/plugins/full-calendar/fullcalendar.min.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('ad/js/plugins/jquery.peity.min.js') }}"></script>
<script type="text/javascript" language="javascript" src="{{ URL::asset('ad/js/plugins/datatables/js/jquery.dataTables.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('ad/js/plugins/chosen/chosen/chosen.jquery.min.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('ad/js/plugins/flot/jquery.flot.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('ad/js/plugins/jquery.uniform.min.js') }}"></script>
<script src="{{ URL::asset('ad/js/plugins/justGage.1.0.1/resources/js/raphael.2.1.0.min.js') }}"></script>
<script src="{{ URL::asset('ad/js/plugins/justGage.1.0.1/resources/js/justgage.1.0.1.min.js') }}"></script>
<script src="{{ URL::asset('ad/js/scripts.js') }}"></script>


    <script type="text/javascript" charset="utf-8">
    // Datatables
    $(document).ready(
            () {
      var dontSort = [];
                $('#datatable_city thead th').each( function () {
                    if ( $(this).hasClass( 'no_sort' )) {
                        dontSort.push( { "bSortable": false } );
                    } else {
                        dontSort.push( null );
                    }
      } );
      $('#datatable_city').dataTable( {
        "sDom": "<'row table_top_bar'<'row-fluid'>'<'to_hide_phone'>'f'<'>r>t<'row'>",
         "sDom": "<'row table_top_bar'<'row-fluid'<'to_hide_phone' f>>><'row'>",
         "aaSorting": [[ 1, "asc" ]],
        "bPaginate": false,
        "bJQueryUI": false,
        "aoColumns": dontSort

      } );
      $.extend( $.fn.dataTableExt.oStdClasses, {
        "s`": "dataTables_wrapper form-inline"
      } );
    } );
    </script>

    <script>

        function select_type(id,type){
            if(confirm("确定要修改此装机的状态吗？")){
                $.post('{{ URL::route('admin.mounts.change') }}',{id : id ,type:type},function(data){
                    if(data == 1){
                        location.reload();
                    }else{
                        alert(data);
                    }
                });
            }
        }
        function select_section(id,type){
            if(confirm("确定要修改用户的直营商吗？")){
                $.post('{{ URL::route('admin.mounts.section') }}',{id : id ,type:type},function(data){
                    if(data == 1){
                        location.reload();
                    }else{
                        alert(data);
                    }
                });
            }
        }
        function select_xiaoqu(id,type){
            if(confirm("确定要修改装机小区吗？")){
                $.post('{{ URL::route('admin.mounts.xiaoqu') }}',{id : id ,type:type},function(data){
                    if(data == 1){
                        location.reload();
                    }else{
                        alert(data);
                    }
                });
            }
        }
        function set_delete(id){
            $('#delete_id').val(id);
        }
        function delete_it(){
            $('#form_delete').submit();
        }
        function export_mounts(){
            var state = $('#export_state').val();
            window.location.href="/admin/services/mounts_export?state="+state;
        }
        function shaixuan_mounts(){
            var state = $('#shaixuan_state').val();
            window.location.href="/admin/services/shaixuan_mounts?from="+state;
        }
    </script>

@stop
